package pl.enigmatic.validation.fields;

import java.util.HashSet;
import java.util.Set;


public class ServerValidator {

	@SuppressWarnings("unchecked")
	public static <T, F extends Enum<F> & Field<T, ?>, E extends Enum<E> & Error<F>> Set<E> validate(final T t, final Class<E> err) {
		final Set<E> errors = new HashSet<E>();
		for (final E e : err.getEnumConstants()) {
			if (!e.getValidator().isValueValid(e.getField().project(t))) {
				errors.add(e);
			}
		}
		return errors;
	}
}
